package com.chaoshi.strategy.impl;

import com.chaoshi.common.FruitPrices;
import com.chaoshi.strategy.PriceStrategy;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 基础策略类
 * 所有水果原价购买
 */
public class AllFruitsStrategy implements PriceStrategy {
    private final FruitPrices prices;

    public AllFruitsStrategy(FruitPrices prices) {
        this.prices = prices;
    }

    public FruitPrices getPrices() {
        return this.prices;
    }

    @Override
    public BigDecimal calculate(int a, int s, int m) {
        BigDecimal appleTotal = prices.getApple().multiply(new BigDecimal(a));
        BigDecimal strawberryTotal = prices.getStrawberry().multiply(new BigDecimal(s));
        BigDecimal mango = prices.getMango().multiply(new BigDecimal(m));
        return appleTotal.add(strawberryTotal).add(mango)
                .setScale(2, RoundingMode.HALF_UP);
    }
}
